package com.qf.drtest;

public class MainTest {

    public static void main(String[] args) throws InterruptedException {
        long start = System.currentTimeMillis();

        Thread t1 = new Thread(){
            @Override
            public void run() {
                //煮饭
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("煮饭....");
            }
        };

        t1.start();

        Thread t2 = new Thread(()->{
            //炒菜
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("炒菜....");
        });

        t2.start();

        //让调用join方法的线程先执行完，然后在继续向下执行代码
        t1.join();
        t2.join();

        //这个开吃的代码应该等待煮饭和炒菜都完成后，才执行（线程间通讯）
        long end = System.currentTimeMillis();
        //开吃
        System.out.println("开吃.... 耗时：" + (end-start)) ;
    }
}
